package com.hdax.dm.api.user.controller;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hdax.dm.api.user.UserControllerApi;
import com.hdax.dm.entity.user.User;
import com.hdax.dm.service.UserService;
import org.apache.catalina.security.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class UserController implements UserControllerApi {

    @Autowired
    private UserService userService;

    @Override
    public User find(String phone) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone",phone);
        User user = userService.getOne(queryWrapper);
        return user;
    }

    @Override
    public boolean register(String phone, String password) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        User user = new User();
        user.setPhone(phone);
        user.setPassword(SecureUtil.md5(password));
        user.setCreatedTime(LocalDateTime.now());
        return userService.save(user);
    }
}
